SOUND_DIR = sound/
include $(SOUND_DIR)Soundfiles

.SFILES		=	crt0.s
.CFILES		=	Main.c Data.c MemDump.c \
			SramTest.c FlashTest.c EepromTest.c DacsTest.c
.OFILES   	=	$(.SFILES:.s=.o) $(.CFILES:.c=.o)

AGBINC		=	$(AGBDIR)/include
AGBLIB		=	$(AGBDIR)/lib

ASFLAGS		=	-I$(AGBINC) -mthumb-interwork

CFLAGS		=	-g -O0 -I$(AGBINC)/backup -Imylib \
			-I$(AGBINC) -mthumb-interwork -nostdlib

LDFLAGS		+=	-Map $(MAPFILE) -nostartfiles \
			-Ttext 0x08000000 -Tbss 0x03000000 \
			-L$(AGBLIB) -lagbsyscall -lisagbprn -lagbbackup \
			-Lmylib -lmyfunc

DEPENDFILE	=	Makedepend
MAPFILE		=	blib_sample.map
TARGET_ELF	=	blib_sample.elf
TARGET_BIN	=	blib_sample.bin


$(TARGET_BIN): $(TARGET_ELF)
	objcopy -v -O binary $< $@

$(TARGET_ELF): $(.OFILES) $(SOUND_FILES) Makefile $(DEPENDFILE)
	@echo > $(MAPFILE)
	$(CC) -g -o $@ $(.OFILES) $(SOUND_FILES) -Wl,$(LDFLAGS)

.PHONY: all clean depend

all:    clean depend $(TARGET_BIN)

clean:
	-rm $(.OFILES) $(DEPENDFILE) $(MAPFILE) $(TARGET_ELF) $(TARGET_BIN)

depend:
	$(CC) $(CFLAGS) -M $(.CFILES) > $(DEPENDFILE) 

$(DEPENDFILE): 
	$(CC) $(CFLAGS) -M $(.CFILES) > $(DEPENDFILE)

include Gasdepend
include $(DEPENDFILE)
